#include "Precompiled.h"
#include "SceneManagerRender.h"

#include "SceneRender.h"
#include "../Common/SceneManager.h"
#include "../Common/EntityRenderManager.h"

namespace Game {
namespace Render {

SceneManagerRender::SceneManagerRender() :
        sceneRender(NULL) {
}

SceneManagerRender::~SceneManagerRender() {
}

const RTTI& SceneManagerRender::GetEntityRTTI() const {
    return SceneManager::rtti;
}

void SceneManagerRender::Draw(DrawableEntity* drawableEntity, const float& elapsedTime) {
    SceneManager* sceneManager = static_cast<SceneManager*>(drawableEntity);
    SceneManagerIterator it(sceneManager);
    for (; it(); ++it) {
        Scene* scene = *it;
        if (scene->GetVisible()) {
            this->sceneRender->Draw(scene, elapsedTime);
        }
    }
}

void SceneManagerRender::OnEntityRenderManagerChanged() {
    IEntityRender* entityRender = this->GetEntityRenderManager()->GetEntityRender(Scene::rtti);
    this->sceneRender = safe_pointer_cast<SceneRender>(entityRender);
}

}
}